package com.bite.system.controller;

import com.bite.common.core.Controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.system.domain.SysUser.TbSysUser;
import com.bite.system.domain.SysUser.dto.LoginDTO;
import com.bite.system.domain.SysUser.dto.SysUserSaveDTO;
import com.bite.system.service.SysUser.ISysUserService;
import com.bite.system.utils.BCryptUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 均先生
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员用户API")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;

    //接口地址：/system/sysUser/login
    @PostMapping("/login")  //安全
    @Operation(summary = "管理员登录", description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户",description = "根据id删除用户")
    @Parameters(value = {@Parameter(name = "userId",in = ParameterIn.PATH,description = "用户Id")})
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public R<Void> delete(@PathVariable Long userId) {
        return null;
    }
}
